import { createRouter, createWebHistory } from 'vue-router'
import { ElMessage } from 'element-plus'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      name: 'Home',
      component: () => import('../views/Home.vue')
    },
    {
      path: '/:department',
      name: 'Report',
      component: () => import('../views/Report.vue'),
      props: true,
      // 只允许指定的部门参数
      beforeEnter: (to, from, next) => {
        const validDepartments = ['medical', 'petition', 'education']
        if (validDepartments.includes(to.params.department)) {
          next()
        } else {
          next('/') // 重定向到首页
        }
      }
    }
  ]
})

//导出路由
export default router 